package grape.crm.rest.customercontact.mvc;

import com.baomidou.mybatisplus.core.metadata.IPage;
import grape.crm.service.customercontact.query.CustomerContactListQuery;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.*;
import com.baomidou.mybatisplus.core.metadata.IPage;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
import javax.validation.Valid;
import grape.crm.rest.customercontact.form.CustomerContactCreateForm;
import grape.crm.rest.customercontact.form.CustomerContactUpdateForm;
import grape.crm.rest.customercontact.form.CustomerContactListPageForm;
import grape.crm.rest.customercontact.vo.CustomerContactVo;
import grape.crm.rest.customercontact.mapper.CustomerContactWebMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RestController;
import grape.common.rest.mvc.BaseController;
import grape.crm.service.customercontact.po.CustomerContact;
import grape.crm.service.customercontact.api.ICustomerContactService;
import java.util.List;
/**
 * <p>
 * 客户联系方式 前端控制器
 * </p>
 *
 * @author yangwei
 * @since 2020-09-14
 */
@RestController
@RequestMapping("/crm/customercontact")
@Api(tags = "客户联系方式相关接口")
public class CustomerContactController extends BaseController<CustomerContactVo, CustomerContact> {

    @Autowired
    private CustomerContactWebMapper currentWebMapper;
    @Autowired
    private ICustomerContactService currentService;



     @ApiOperation("添加客户联系方式")
     @PreAuthorize("hasAuthority('customercontact:single:create')")
     @PostMapping
     @ResponseStatus(HttpStatus.CREATED)
     public CustomerContactVo create(@RequestBody @Valid CustomerContactCreateForm cf) {
         CustomerContact po = currentWebMapper.formToPo(cf);
         return super.create(po);
     }

     @ApiOperation("根据ID查询客户联系方式")
     @PreAuthorize("hasAuthority('customercontact:single:queryById')")
     @GetMapping("/{id}")
     @ResponseStatus(HttpStatus.OK)
     public CustomerContactVo queryById(@PathVariable String id) {
         return super.queryById(id);
     }

     @ApiOperation("删除客户联系方式")
     @PreAuthorize("hasAuthority('customercontact:single:deleteById')")
     @DeleteMapping("/{id}")
     @ResponseStatus(HttpStatus.NO_CONTENT)
     public boolean deleteById(@PathVariable String id) {
         return super.deleteById(id);
     }

     @ApiOperation("更新客户联系方式")
     @PreAuthorize("hasAuthority('customercontact:single:updateById')")
     @PutMapping("/{id}")
     @ResponseStatus(HttpStatus.CREATED)
     public CustomerContactVo update(@PathVariable String id,@RequestBody @Valid CustomerContactUpdateForm uf) {
         CustomerContact po = currentWebMapper.formToPo(uf);
         po.setId(id);
         return super.update(po);
     }

    @ApiOperation("分页查询客户联系方式")
    @PreAuthorize("hasAuthority('customercontact:single:listPage')")
    @GetMapping("/listPage")
    @ResponseStatus(HttpStatus.OK)
    public IPage<CustomerContactVo> listPage(CustomerContactListPageForm listPageForm) {
         CustomerContact po = currentWebMapper.formToPo(listPageForm);
        CustomerContactListQuery customerContactListQuery = new CustomerContactListQuery();
        customerContactListQuery.setPoQuery(po);
        return super.listPage(customerContactListQuery,listPageForm);
     }

}
